package com.heraleign.mybatis.controller;

import com.heraleign.mybatis.bean.Student;
import com.heraleign.mybatis.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("student")
@Api(tags={"学生管理控制器"})
public class StudentController {
    @Resource
    private StudentService service;

    @ApiOperation("显示全部学生信息")
    @GetMapping
    public Object list(){
        List<Student> list=service.selectList();
        return list;
    }

    @ApiOperation("根据Id查找学生信息")
    @GetMapping("/{id}")
    public Object selectStuById(@PathVariable Integer id){
        return service.selectStuById(id);
    }

    @ApiOperation("保存学生信息")
    @PostMapping
    public Object save(@RequestBody Student student){
        return service.saveStu(student);
    }

    @ApiOperation("修改学生信息")
    @PutMapping
    public Object update(@RequestBody Student student){
        return service.updateStu(student);
    }

    @ApiOperation("根据Id删除学生信息")
    @DeleteMapping("/{id}")
    public Object delete(@PathVariable Integer id){
        return service.deleteById(id);
    }

    @ApiOperation("根据学生姓名查学生")
    @PostMapping("/queryStudentByName")
    public Object query( String stuName){
        return service.queryStudentByName(stuName);
    }

    @ApiOperation("根据学生姓名查学生2")
    @PostMapping("/queryStudentByName2")
    public Object query2(@RequestBody String stuName){
        return service.queryStudentByName(stuName);
    }
}
